{% extends "_base.html" %}
{% block title %}
    {% if is_self %}
        我的个人主页
    {% else %}
        {{user_info['username']}}的个人主页
    {% endif %}
{% endblock %}
{% block script %}
<script type="text/javascript" src="/static/script/Validate.js"></script>
<script type="text/javascript" src="/static/script/Page.js"></script>
<script>
$(function(){
    // 初始化列表
    var items_own = [
        {% for item_info in item_own_infos %}
            {
                "id": "{{item_info['id']}}",
                "itemname": "{{item_info['itemname']}}",
                "price": {{item_info['price']}},
                "tags": "{{', '.join(item_info['tags'])}}",
                "add_time": "{{item_info['add_time']}}",
                "owner_id": {{item_info['owner_id']}},
                {% if not item_info['buyer_id'] %}
                    "special": "del",
                {% elif is_self %}
                    "special": "connect",
                    "buyer_info": {
                        {% for key, value in item_info['buyer_info'].iteritems() %}
                            "{{key}}": "{{value}}",
                        {% endfor %}
                    },
                {% endif%}
            },
        {% endfor %}
        ];
    item_fill(items_own, "#item-own-list");
    var items_buy = [
        {% for item_info in item_buy_infos %}
            {
                "id": "{{item_info['id']}}",
                "itemname": "{{item_info['itemname']}}",
                "price": {{item_info['price']}},
                "tags": "{{', '.join(item_info['tags'])}}",
                "add_time": "{{item_info['add_time']}}",
                "owner_id": {{item_info['owner_id']}},
            },
        {% endfor %}
        ];
    item_fill(items_buy, "#item-buy-list");

    // 注册按钮事件
    $(".item-button-detail").click(function(){
        link = $(this).attr("rel");
        location.href = link;
    });
    $(".item-button-special").click(function(){
        link = $(this).attr("rel");
        location.href = link;
    });
});
</script>
{% endblock %}
{% block content %}
<!-- 列表模板，已隐藏 -->
<ul id="item-list-template">
    <li class="item-li" id="item-li-template">
        <div class="item-div-left">
            <img class="item-photo" src="" title="商品图片" />
        </div>
        <div class="item-div-middle">
            <div class="item-describe-row">
                <label class="item-title">商品名称：</label>
                <label class="item-value  item-name"></label>
            </div>
            <div class="item-describe-row">
                <label class="item-title">商品标签：</label>
                <label class="item-value item-tags"></label>
            </div>
            <div class="item-describe-row">
                <label class="item-title">商品价格：</label>
                <label class="item-value"><strong class="item-price"></strong>元</label>
            </div>
            <div class="item-describe-row">
                <label class="item-title">添加时间：</label>
                <label class="item-value item-time"></label>
            </div>
        </div>
        <div class="item-div-right">
            <div class="item-button-row">
                <button type="button" class="item-button item-button-detail" rel="/show?id=1">详情</button>
            </div>
            <div class="item-button-row item-button-row-special">
                <button type="button" class="item-button item-button-special">购买</button>
            </div>
        </div>
    </li>
</ul>
<!-- 显示的列表，动态填充 -->
<h2>拥有的商品</h2>
<ul id="item-own-list" class="item-ul">
</ul>
<ul id="page-row">
    {% for offset in range(0, item_own_count, page_size) %}
        <li
        onclick="ajaxGetPage(this, {{loop.index}}, '/item/list/?id={{user_info['id']}}&type=own&offset={{offset}}&num={{page_size}}', '#item-own-list')" 
        {% if loop.first %}
            class="page-current"
        {% endif %}
        >{{loop.index}}</li>
    {% endfor %}
</ul>
<h2>买到的商品</h2>
<ul id="item-buy-list" class="item-ul">
</ul>
<ul id="page-row">
    {% for offset in range(0, item_buy_count, page_size) %}
        <li
        onclick="ajaxGetPage(this, {{loop.index}}, '/item/list/?id={{user_info['id']}}&type=buy&offset={{offset}}&num={{page_size}}', '#item-buy-list')" 
        {% if loop.first %}
            class="page-current"
        {% endif %}
        >{{loop.index}}</li>
    {% endfor %}
</ul>
{% endblock %}
